package com.qianfeng.openplatform.geteway.listen;

import com.qianfeng.openplatform.commons.field.RedisKeyPrefix;
import com.qianfeng.openplatform.commons.field.util.AppTowCacheUtil;
import com.qianfeng.openplatform.geteway.client.CacheClient;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.Map;
import java.util.Set;



/**
 * @author 江江
 * @Date 2020/7/28 16:58
 */
@WebListener
public class CacheRoutingBen implements ServletContextListener {
    @Autowired
    private CacheClient cacheClient;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("CacheRoutingBen==>被加载了===========================");
        try {
            Set<String> keys = cacheClient.findKeyByPartten(RedisKeyPrefix.WEB_MASTER_API_MAPPING_HASH_PRE + "*");
            for (String key : keys) {
                Map<Object, Object> map = cacheClient.hGetAll(key);
                AppTowCacheUtil.cacheRoutingMap.put(key,map);
            }
            System.out.println(AppTowCacheUtil.cacheRoutingMap);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
